from scapy.all import *
import scapy
import sys, os
from scapy.layers.l2 import Ether

TYPE_NDN = 0x8624


# append


class NDNData(Packet):
    name = "NDNData"
    fields_desc = [  # value,length
        BitField("TLV_0_Type", 06, 8),  # 05:Data
        BitField("LV_0_Length", 94, 8),  # 2+4*10+6+6+2+3+2+32 87/1083
        BitField("Name_Type", 07, 8),  # 07:Name
        BitField("Name_Length", 45, 8),  # 4*8=32 that means 8 Character like "beijing0"
        BitField("Component1_Type", 8, 8),
        BitField("Component1_Length", 8, 8),
        BitField("Component1", 0, 64),
        BitField("Component2_Type", 8, 8),
        BitField("Component2_Length", 8, 8),
        BitField("Component2", 0, 64),
        BitField("Component3_Type", 8, 8),
        BitField("Component3_Length", 8, 8),
        BitField("Component3", 0, 64),
        BitField("Componentv_Type", 8, 8),
        BitField("Componentv_Length", 9, 8),
        BitField("Componentv", 0, 72),
        BitField("Componentn_Type", 8, 8),
        BitField("Componentn_Length", 2, 8),
        BitField("Componentn", 0, 16),
        # BitField("MetaInfo_Type", 20, 8),  # MetaInfo
        # BitField("MetaInfo_Length", 4, 8),
        # BitField("FreshnessPeriod_Type", 25, 8),
        # BitField("FreshnessPeriod_Length", 2, 8),
        # BitField("FreshnessPeriod", 10000, 16),
        BitField("Content_Type", 21, 8),  # real content
        BitField("Content_Length", 8, 8),
        BitField("Content", 0, 64),  # remain to be set
        BitField("Signature_info_Type", 22, 8),
        BitField("Signature_info_Length", 3, 8),
        BitField("Signature_type_Type", 27, 8),
        BitField("Signature_type_Length", 1, 8),
        BitField("NonNegativeInteger", 0, 8),
        BitField("Signature_Value_Type", 23, 8),
        BitField("Signature_Value_Length", 32, 8),
        BitField("Signature_Value", 0, 256),  # set in sender
    ]

    def mysummary(self):
        return self.sprintf("Component1=%Component1%, Signature=%Signature%")


# bind_layers(Ether, NDNData, type=TYPE_NDN)
